// import es6 from '../../vendor/promise/es6-promise'
import Config from './Config'

class NTPromise {
  constructor() {
  }

  ajax(method, options) {
    return new Promise((resolve, reject) => {
      let url  = options.url || ''
      wx.request({
        url: url.startsWith('http') ? url : Config.api_base + url,
        data: options.params,
        method: method, // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
        header: options.headers || {},
        success: (res) => {
          resolve && resolve(res)
        },
        fail: (err) => {
          reject && reject(err)
        }
      })
    })
  }

  action(fn){
    return new Promise(fn)
  }
}

export default NTPromise
